define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'store/store/index' + location.search,
                    // add_url: 'store/store/add',
                    edit_url: 'store/store/edit',
                    del_url: 'store/store/del',
                    multi_url: 'store/store/multi',
                    import_url: 'store/store/import',
                    table: 'store',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'store_id',
                sortName: 'store_id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'store_id', title: __('Store_id')},
                        {field: 'uid', title: __('Uid')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'homediv', title: __('覆盖范围'), operate: 'LIKE'},
                        {field: 'store_address', title: __('Store_address'), operate: 'LIKE'},
                        {field: 'hours_start', title: __('Hours_start'), operate: 'LIKE'},
                        {field: 'hours_end', title: __('Hours_end'), operate: 'LIKE'},
                        {field: 'serve_phone', title: __('Serve_phone'), operate: 'LIKE'},
                        {field: 'serve_image', title: __('Serve_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'store_introduction', title: __('Store_introduction'), operate: 'LIKE'},
                        {field: 'store_welcomes', title: __('Store_welcomes'), operate: 'LIKE'},
                        {field: 'store_recruit', title: __('Store_recruit'), operate: 'LIKE',events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'scope', title: __('Scope'), operate: 'LIKE'},
                        {field: 'store_code', title: __('Store_code'), operate: 'LIKE'},
                        {field: 'is_check', title: __('Is_check'), searchList: {"0":__('Is_check 0'),"1":__('Is_check 1')}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'store_grade', title: __('Store_grade'), operate: 'LIKE'},
                        {field: 'lincense', title: __('Lincense'), operate: 'LIKE',events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'lon', title: __('Lon'), operate: 'LIKE'},
                        {field: 'lat', title: __('Lat'), operate: 'LIKE'},
                        // {field: 'feedback', title: __('Feedback'), operate: 'LIKE'},
                        // {field: 'order_rate', title: __('Order_rate'), operate: 'LIKE'},
                        // {field: 'sales', title: __('Sales')},
                        // {field: 'qrcode_url', title: __('Qrcode_url'), operate: 'LIKE', formatter: Table.api.formatter.url},
                        {field: 'company_name', title: __('Company_name'), operate: 'LIKE'},
                        {field: 'phone', title: __('Phone'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
